********************************
* 6. ANALYSIS OF WORLD DATASET *
********************************

***********************************************
* CONTENT:	(1) Descriptive statistics        *
*           (2) Checks                        *
*           (3) Results                       *
* 			(4) Comparison with raw estimates *
***********************************************

set more off

use WPO_world_data_10k_bis.dta, clear

* (1) Descriptive statistics
****************************

* Rounding variables

replace female=round(female)
replace female=0 if female<0
replace female=1 if female>1

replace education=round(education)
replace education=1 if education<1
replace education=10 if education>10

replace age=round(age)
replace age=1 if age<1
replace age=6 if age>6

replace urban=round(urban)
replace urban=1 if urban<1
replace urban=6 if urban>6

replace income=round(income)
replace income=1 if income<1
replace income=10 if income>10

* Descriptive stats

sum female age education urban income 
corr female education age urban income

* Saving

save WPO_world_data_10k_bis.dta, replace

* (2) Checks
************

* Creating a variable capturing whether the synthetic humans is between 15 and 64, or 65+

gen age_1564=1
replace age_1564=0 if age==6
replace age_1564=. if age==.

gen age_65=0
replace age_65=1 if age==6
replace age_65=. if age==.

* Calculating for each country-year, the proportion of humabs between 15 ans 64, and 65+ (by country year)

bysort country_id: egen age1564_mean_humanity=mean(age_1564)
bysort country_id: egen age65_mean_humanity=mean(age_65)

* Sorting and merging with QOG dataset

sort country year
merge m:1 country year using QOG_reduced.dta, nogen

* Dropping years not covered in analysis

drop if year<1994
drop if year>2020

* Calculating number and proportion of people in the world between 15 and 64, and above 65 according to official statistics (by country year)

gen qog_1564=wdi_pop1564*wdi_pop
gen qog_65=wdi_pop65*wdi_pop

gen qog_1564_prop=qog_1564/(qog_1564+qog_65)
gen qog_65_prop=qog_65/(qog_1564+qog_65)

* Creating inclusion variables

gen WVS_included=1
replace WVS_included=0 if age_mean==.
replace WVS_included=0 if edu_mean==.
replace WVS_included=0 if female_mean==.
replace WVS_included=0 if urban_mean==.
replace WVS_included=0 if income_mean==.

bysort country: egen max_inclusion=max(WVS_included)
gen WVS_included_totally=0
replace WVS_included_totally=1 if max_inclusion==1

* Keeping one observation by country year

bysort country year: gen group_id=1 if _n==1
keep if group_id==1

* Results: correlations

corr age65_mean_humanity qog_65_prop if WVS_included==1
corr age65_mean_humanity qog_65_prop if WVS_included==0 & WVS_included_totally==1
corr age65_mean_humanity qog_65_prop if WVS_included_totally==0

* Plotting the results

graph twoway (scatter qog_1564_prop age1564_mean_humanity if WVS_included==1, scheme(s2mono)) (lfit qog_1564_prop age1564_mean_humanity if WVS_included==1, lcolor(red)), ytitle("Prop of people aged 15-64 (official)") xtitle("Prop of people aged 15-64 (humanity)") title("Included in WVS", color(black)) note("Corr = 0.95", size(medium) c(black) margin(t=3)) legend(off) xlabel(0.7(.1)1) ylabel(0.7(.1)1) graphregion(color(white)) 

graph save Age1564_Prop_cov.gph, replace

graph twoway (scatter qog_1564_prop age1564_mean_humanity if WVS_included==0 & WVS_included_totally==1,  scheme(s2mono)) (lfit qog_1564_prop age1564_mean_humanity if WVS_included==0, lcolor(red)), ytitle("Prop of people aged 15-64 (official)") xtitle("Prop of people aged 15-64 (humanity)") title("Not included in WVS", color(black)) note("Corr = 0.96", size(medium) c(black) margin(t=3)) legend(off) xlabel(0.7(.1)1) ylabel(0.7(.1)1) graphregion(color(white)) 

graph save Age1564_Prop_notcov.gph, replace

graph twoway (scatter qog_1564_prop age1564_mean_humanity if WVS_included==0,  scheme(s2mono)) (lfit qog_1564_prop age1564_mean_humanity if WVS_included_totally==0, lcolor(red)), ytitle("Prop of people aged 15-64 (official)") xtitle("Prop of people aged 15-64 (humanity)") title("Never included in WVS", color(black)) note("Corr = 0.92", size(medium) c(black) margin(t=3)) legend(off) xlabel(0.7(.1)1) ylabel(0.7(.1)1) graphregion(color(white)) 

graph save Age1564_Prop_notcov2.gph, replace

graph combine "Age1564_Prop_cov.gph" "Age1564_Prop_notcov.gph" "Age1564_Prop_notcov2.gph", graphregion(color(white)) row(1) xsize(8)
graph export age.png, replace

* Correlation in some selected countries

use WPO_world_data_10k_bis.dta, clear

keep if country==528 | country==56 | country==508 | country==566

corr female education age urban income if country==508 // Mozambique
corr female education age urban income if country==566 // Nigeria (covered)
corr female education age urban income if country==56 // Belgium
corr female education age urban income if country==528 // Netherlands (covered)

* (3) Analysis
**************

* Descriptive statistics

use WPO_world_data_10k_bis.dta, clear

gen E114_simulation_d=1 if E114_simulation<1.5
replace E114_simulation_d=2 if E114_simulation>=1.5 & E114_simulation<2.5
replace E114_simulation_d=3 if E114_simulation>=2.5 & E114_simulation<3.5
replace E114_simulation_d=4 if E114_simulation>=3.5

gen E117_simulation_d=1 if E117_simulation<1.5
replace E117_simulation_d=2 if E117_simulation>1.5 & E117_simulation<2.5
replace E117_simulation_d=3 if E117_simulation>2.5 & E117_simulation<3.5
replace E117_simulation_d=4 if E117_simulation>3.5

gen D059_simulation_d=1 if D059_simulation<1.5
replace D059_simulation_d=2 if D059_simulation>1.5 & D059_simulation<2.5
replace D059_simulation_d=3 if D059_simulation>2.5 & D059_simulation<3.5
replace D059_simulation_d=4 if D059_simulation>3.5

sum E114_simulation E117_simulation D059_simulation
corr E114_simulation E117_simulation D059_simulation

* Histograms

twoway (hist E114_simulation_d, percent graphregion(color(white)) xlabel(1(1)4) xtitle("Support for strong leader") discrete barwidth(.5) yaxis(1) ytitle("Percent (discrete)", axis(1))) (hist E114_simulation if E114_simulation<4.001 & E114_simulation>0.999, percent graphregion(color(white)) xlabel(1(1)4) xtitle("Support for strong leader") recast(line) bin(20) yaxis(2) ytitle("Percent (continuous)", axis(2))), scheme(s2mono) legend(off)
graph save p1.gph, replace

twoway (hist E117_simulation_d, percent graphregion(color(white)) xlabel(1(1)4) xtitle("Support for strong leader") discrete barwidth(.5) yaxis(1) ytitle("Percent (discrete)", axis(1))) (hist E117_simulation if E117_simulation<4.001 & E117_simulation>0.999, percent graphregion(color(white)) xlabel(1(1)4) xtitle("Support for democracy") recast(line) bin(20) yaxis(2) ytitle("Percent (continuous)", axis(2))), scheme(s2mono) legend(off)
graph save p2.gph, replace

twoway (hist D059_simulation_d, percent graphregion(color(white)) xlabel(1(1)4) xtitle("Support for male leader") discrete barwidth(.5) yaxis(1) ytitle("Percent (discrete)", axis(1))) (hist D059_simulation if D059_simulation<4.001 & D059_simulation>0.999, percent graphregion(color(white)) xlabel(1(1)4) xtitle("Support for democracy") recast(line) bin(20) yaxis(2) ytitle("Percent (continuous)", axis(2))), scheme(s2mono) legend(off)
graph save p3.gph, replace

graph combine "p1.gph" "p2.gph" "p3.gph", row(3) graphregion(color(white))
graph display, ysize(10)
graph export result1.png, replace


* By year

use WPO_world_data_10k_bis.dta, clear

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Support for strong leader") ytitle("", axis(1)) ysize(3)  xtitle("Year")
graph save p1.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Support for democracy") ytitle("", axis(1))  ysize(3)  xtitle("Year")
graph save p2.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Support for male leader") ytitle("", axis(1)) ysize(3)  xtitle("Year")
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, row(1) graphregion(color(white))
graph export result2.png, replace

* By region

use WPO_world_data_10k_bis.dta, clear

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(ht_region)
serrbar E114_mean E114_sd ht_region if ht_region>=1 & ht_region<=8, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for strong leader") ytitle("", axis(1)) xlabel(1 "Eastern Europe/Post-soviet Union" 2 "Latin America" 3 "North Africa/Middle East" 4 "Sub-saharan Africa" 5 "Western Europe/North America" 6 "East Asia" 7 "South East Asia" 8"South Asia", angle(90) labsize(small)) xtitle("")
graph save p1.gph, replace

serrbar E117_mean E117_sd ht_region if ht_region>=1 & ht_region<=8, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for democracy") ytitle("", axis(1)) xlabel(1 "Eastern Europe/Post-soviet Union" 2 "Latin America" 3 "North Africa/Middle East" 4 "Sub-saharan Africa" 5 "Western Europe/North America" 6 "East Asia" 7 "South East Asia" 8"South Asia", angle(90) labsize(small)) xtitle("")
graph save p2.gph, replace

serrbar D059_mean D059_sd ht_region if ht_region>=1 & ht_region<=8, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for male leader") ytitle("", axis(1)) xlabel(1 "Eastern Europe/Post-soviet Union" 2 "Latin America" 3 "North Africa/Middle East" 4 "Sub-saharan Africa" 5 "Western Europe/North America" 6 "East Asia" 7 "South East Asia" 8"South Asia", angle(90) labsize(small)) xtitle("")
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, row(1) graphregion(color(white))
graph export result3.png, replace

* By age

use WPO_world_data_10k_bis.dta, clear

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(age)
serrbar E114_mean E114_sd age, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for strong leader") ytitle("", axis(1)) xtitle("Age group") xlabel(1 "15-24" 2"25-34" 3"35-44" 4"45-54" 5"55-64" 6"65+", angle(90))
graph save p1.gph, replace

serrbar E117_mean E117_sd age, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for democracy") ytitle("", axis(1)) xtitle("Age group") xlabel(1 "15-24" 2"25-34" 3"35-44" 4"45-54" 5"55-64" 6"65+", angle(90))
graph save p2.gph, replace

serrbar D059_mean D059_sd age, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for male leader") ytitle("", axis(1)) xtitle("Age group") xlabel(1 "15-24" 2"25-34" 3"35-44" 4"45-54" 5"55-64" 6"65+", angle(90))
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, row(1) graphregion(color(white))
graph export result4.png, replace

*  By gender

use WPO_world_data_10k_bis.dta, clear

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(female)
serrbar E114_mean E114_sd female, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for strong leader") ytitle("", axis(1)) xtitle("") xlabel(0 "Male" 1"Female", angle(90))
graph save p1.gph, replace

serrbar E117_mean E117_sd female, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for democracy") ytitle("", axis(1)) xtitle("") xlabel(0 "Male" 1"Female", angle(90))
graph save p2.gph, replace

serrbar D059_mean D059_sd female, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for male leader") ytitle("", axis(1)) xtitle("") xlabel(0 "Male" 1"Female", angle(90))
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, row(1) graphregion(color(white))
graph export result5.png, replace


*  By urban

use WPO_world_data_10k_bis.dta, clear

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(urban)
serrbar E114_mean E114_sd urban, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for strong leader") ytitle("", axis(1)) xtitle("Place of residence") xlabel(1 "1: Very small town" 2"2" 3"3" 4"4" 5"5" 6"6: Very big city", angle(90))
graph save p1.gph, replace

serrbar E117_mean E117_sd urban, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for democracy") ytitle("", axis(1)) xtitle("Place of residence") xlabel(1 "1: Very small town" 2"2" 3"3" 4"4" 5"5" 6"6: Very big city", angle(90))
graph save p2.gph, replace

serrbar D059_mean D059_sd urban, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) title("Support for male leader") ytitle("", axis(1)) xtitle("Place of residence") xlabel(1 "1: Very small town" 2"2" 3"3" 4"4" 5"5" 6"6: Very big city", angle(90))
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, row(1) graphregion(color(white))
graph export result6.png, replace


*  By year, region

use WPO_world_data_10k_bis.dta, clear

keep if ht_region==5 // The West

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Western countries") ytitle("", axis(1))
graph save p1_west.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Western countries") ytitle("", axis(1))
graph save p2_west.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Western countries") ytitle("", axis(1))
graph save p3_west.gph, replace

use WPO_world_data_10k_bis.dta, clear

keep if ht_region==2 // Latin America

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Latin America") ytitle("", axis(1))
graph save p1_la.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Latin America") ytitle("", axis(1))
graph save p2_la.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Latin America") ytitle("", axis(1))
graph save p3_la.gph, replace

use WPO_world_data_10k_bis.dta, clear

keep if ht_region==3 | ht_region==4 // Africa

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Africa") ytitle("", axis(1))
graph save p1_africa.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Africa") ytitle("", axis(1))
graph save p2_africa.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Africa") ytitle("", axis(1))
graph save p3_africa.gph, replace


use WPO_world_data_10k_bis.dta, clear

keep if ht_region==6 | ht_region==7 | ht_region==8 // Asia

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Asia") ytitle("", axis(1))
graph save p1_asia.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Asia") ytitle("", axis(1))
graph save p2_asia.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Asia") ytitle("", axis(1))
graph save p3_asia.gph, replace

graph combine p1_west.gph p1_asia.gph p1_africa.gph p1_la.gph, row(1) title("Support for strong leader", color(black)) graphregion(color(white)) ysize(3)
graph export strongleader_year.png, replace

graph combine p2_west.gph p2_asia.gph p2_africa.gph p2_la.gph, row(1) title("Support for democracy", color(black)) graphregion(color(white)) ysize(3)
graph export democracy_year.png, replace

graph combine p3_west.gph p3_asia.gph p3_africa.gph p3_la.gph, row(1) title("Support for male leader", color(black)) graphregion(color(white)) ysize(3)
graph export maleleader_year.png, replace

* By democracy, year

use WPO_world_data_10k_bis.dta, clear

gen dem_binary=.
replace dem_binary=0 if vdem_libdem<0.36
replace dem_binary=1 if vdem_libdem>0.36


keep if dem_binary==1

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Democracies") ytitle("", axis(1))
graph save p1_dem.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Democracies") ytitle("", axis(1))
graph save p2_dem.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Democracies") ytitle("", axis(1))
graph save p3_dem.gph, replace


use WPO_world_data_10k.dta, clear

gen dem_binary=.
replace dem_binary=0 if vdem_libdem<0.093
replace dem_binary=1 if vdem_libdem>0.627


keep if dem_binary==0

collapse (mean) E114_mean = E114_simulation (sd) E114_sd = E114_simulation (mean) E117_mean = E117_simulation (sd) E117_sd = E117_simulation (mean) D059_mean = D059_simulation (sd) D059_sd = D059_simulation, by(year)

serrbar E114_mean E114_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Non-democracies") ytitle("", axis(1))
graph save p1_nondem.gph, replace

serrbar E117_mean E117_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Non-democracies") ytitle("", axis(1))
graph save p2_nondem.gph, replace

serrbar D059_mean D059_sd year if year>=1994 & year<=2020, scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Non-democracies") ytitle("", axis(1))
graph save p3_nondem.gph, replace


graph combine p1_dem.gph p1_nondem.gph, row(1) title("Support for strong leader", color(black)) graphregion(color(white)) ysize(3)
graph export strongleader_dem.png, replace

graph combine p2_dem.gph p2_nondem.gph, row(1) title("Support for democracy", color(black)) graphregion(color(white)) ysize(3)
graph export democracy_dem.png, replace

graph combine p3_dem.gph p3_nondem.gph, row(1) title("Support for male leader", color(black)) graphregion(color(white)) ysize(3)
graph export maleleader_dem.png, replace


* (4) Comparison with raw estimates
***********************************

* Loading WVS dataset

use WPO_WVS_QOG.dta, replace

* Calculating raw mean

collapse (mean) E114_mean_raw = E114_clean (mean) E117_mean_raw = E117_clean (mean) D059_mean_raw = D059_clean, by(year)
drop if year<1994
drop if year>2020

* Saving

save raw.dta, replace

* Loading WVS dataset

use WPO_WVS_QOG.dta, replace

* Calculating raw mean (E114)

collapse (mean) E114_mean_raw2 = E114_clean [aw=wdi_pop], by(year)
drop if year<1994
drop if year>2020

* Saving

save raw2.dta, replace

* Loading WVS dataset

use WPO_WVS_QOG.dta, replace

* Calculating raw mean (E117)

collapse (mean) E117_mean_raw2 = E117_clean [aw=wdi_pop], by(year)
drop if year<1994
drop if year>2020

* Saving

save raw3.dta, replace

* Loading WVS dataset

use WPO_WVS_QOG.dta, replace

* Calculating raw mean (D059)

collapse (mean) D059_mean_raw2 = D059_clean [aw=wdi_pop], by(year)
drop if year<1994
drop if year>2020

* Saving

save raw4.dta, replace


* Loading the humanity dataset

use WPO_world_data_10k_bis.dta, clear

* Calculating mean
 
collapse (mean) E114_mean = E114_simulation (mean) E117_mean = E117_simulation (mean) D059_mean = D059_simulation, by(year)

* Merging the two

merge 1:1 year using raw.dta, nogen
merge 1:1 year using raw2.dta, nogen
merge 1:1 year using raw3.dta, nogen
merge 1:1 year using raw4.dta, nogen

* Drawing plots

twoway (line E114_mean year, legend(label(1 "Humanity") col(1)) lp(solid) lw(thick) scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Support for strong leader") xtitle("Year") ytitle("", axis(1))) (line E114_mean_raw year, legend(label(2 "WVS raw") col(1)) lp(solid) lw(normal)) (line E114_mean_raw2 year, legend(label(3 "WVS weighted") col(1)) lp(dash) lw(normal)) 
graph save p1.gph, replace

twoway (line E117_mean year, legend(label(1 "Humanity") col(1)) lp(solid) lw(thick) scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Support for democracy") xtitle("Year") ytitle("", axis(1))) (line E117_mean_raw year, legend(label(2 "WVS raw") col(1)) lp(solid) lw(normal)) (line E117_mean_raw2 year, legend(label(3 "WVS weighted") col(1)) lp(dash) lw(normal)) 
graph save "p2.gph, replace

twoway (line D059_mean year, legend(label(1 "Humanity") col(1)) lp(solid) lw(thick) scheme(s2mono) graphregion(color(white)) ylabel(1(1)4) xlabel(1995(5)2020, angle(90)) title("Support for male leader") xtitle("Year") ytitle("", axis(1))) (line D059_mean_raw year, legend(label(2 "WVS raw") col(1)) lp(solid) lw(normal)) (line D059_mean_raw2 year, legend(label(3 "WVS weighted") col(1)) lp(dash) lw(normal)) 
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, row(1) title("") graphregion(color(white))
graph export compare.png, replace
